﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.Data.SqlClient;
namespace Team4Mock.DAO
{
    public class OrganisationDAO
    {
        private Helper h = new Helper();

        public DataTable Getdata()
        {
            return h.GetData("Org_Getdata");
        }

        public DataTable GetdataTrue()
        {
            return h.GetData("Org_GetdataTrue");
        }

        public DataTable GetCountry()
        {
            return h.GetData("Org_GetCountry");
        }

        public DataTable GetOrgSpec()
        {
            return h.GetData("Org_GetOrgSpec");
        }
        public void Del(int id)
        {
            SqlParameter[] p = new SqlParameter[1];
            p[0] = new SqlParameter("@id",id);
            p[0].SqlDbType = SqlDbType.Int;
            h.ExecuteNonQuerry("Org_Del",p);
        }
        public DataTable GetAccred()
        {
            return h.GetData("Org_GetAccred");
        }

        public DataTable GetSerBarrieCapa()
        {
            return h.GetData("Org_GetSerBarrieCapa");
        }

        public DataTable GetSerBenifitCapa()
        {
            return h.GetData("Org_GetSerBenifitCapa");
        }

        public DataTable GetSerDisaCapa()
        {
            return h.GetData("Org_GetSerDisaCapa");
        }
        public DataTable GetOEOIPro()
        {
            return h.GetData("Org_GetOEOIPro");
        }
        public DataTable GetOEOISer()
        {
            return h.GetData("Org_GetOEOISer");
        }

        public DataTable GetSerPersoCapa()
        {
            return h.GetData("Org_GetSerPersoCapa");
        }

        public DataTable GetEthicCapa()
        {
            return h.GetData("Org_GetEthnicCapa");
        }

        public int Getid()
        {
            return h.GetValueInt("Org_GetID");
        }

        public DataTable Search(string key)
        {
            SqlParameter[] p = new SqlParameter[1];
            p[0] = new SqlParameter("@key", key);
            p[0].SqlDbType = SqlDbType.VarChar;
            return h.GetData("Org_Search", p);
        }
        public DataTable SearchTrue(string key)
        {
            SqlParameter[] p = new SqlParameter[1];
            p[0] = new SqlParameter("@key", key);
            p[0].SqlDbType = SqlDbType.VarChar;
            return h.GetData("Org_SearchTrue", p);
        }

        public void InsertOrg(string orgName, string shortDesc, int contactId, string add1, string add2, string add3,
                              string postcode, string town, string county, string country, int Preferred, int Express,
                              string typebus, string sic, string fullDes, string phone, string fax, string web,
                              string charty, string company, int active)
        {
            SqlParameter[] p = new SqlParameter[21];
            p[0] = new SqlParameter("@orgName", orgName);
            p[0].SqlDbType = SqlDbType.NVarChar;
            p[1] = new SqlParameter("@shortDes", shortDesc);
            p[1].SqlDbType = SqlDbType.NVarChar;
            p[2] = new SqlParameter("@contactID", contactId);
            p[2].SqlDbType = SqlDbType.Int;
            p[3] = new SqlParameter("@add1", add1);
            p[3].SqlDbType = SqlDbType.NVarChar;
            p[4] = new SqlParameter("@add2", add2);
            p[4].SqlDbType = SqlDbType.NVarChar;
            p[5] = new SqlParameter("@add3", add3);
            p[5].SqlDbType = SqlDbType.NVarChar;
            p[6] = new SqlParameter("@postcode", postcode);
            p[6].SqlDbType = SqlDbType.VarChar;
            p[7] = new SqlParameter("@town", town);
            p[7].SqlDbType = SqlDbType.NVarChar;
            p[8] = new SqlParameter("@county", county);
            p[8].SqlDbType = SqlDbType.NVarChar;
            p[9] = new SqlParameter("@country", country);
            p[9].SqlDbType = SqlDbType.NVarChar;
            p[10] = new SqlParameter("@preferred", Preferred);
            p[10].SqlDbType = SqlDbType.Int;
            p[11] = new SqlParameter("@express", Express);
            p[11].SqlDbType = SqlDbType.Int;
            p[12] = new SqlParameter("@typebus", typebus);
            p[12].SqlDbType = SqlDbType.VarChar;
            p[13] = new SqlParameter("@sic", sic);
            p[13].SqlDbType = SqlDbType.VarChar;
            p[14] = new SqlParameter("@fulldes", fullDes);
            p[14].SqlDbType = SqlDbType.NVarChar;
            p[15] = new SqlParameter("@phone", phone);
            p[15].SqlDbType = SqlDbType.VarChar;
            p[16] = new SqlParameter("@fax", fax);
            p[16].SqlDbType = SqlDbType.VarChar;
            p[17] = new SqlParameter("@web", web);
            p[17].SqlDbType = SqlDbType.VarChar;
            p[18] = new SqlParameter("@charty", charty);
            p[18].SqlDbType = SqlDbType.VarChar;
            p[19] = new SqlParameter("@company", company);
            p[19].SqlDbType = SqlDbType.VarChar;
            p[20] = new SqlParameter("@active", active);
            p[20].SqlDbType = SqlDbType.Int;
            h.ExecuteNonQuerry("Org_Insert", p);
        }

        public void UpdateOrg(string orgName, string shortDesc, int contactId, string add1, string add2, string add3,
                              string postcode, string town, string county, string country, int Preferred, int Express,
                              string typebus, string sic, string fullDes, string phone, string fax, string web,
                              string charty, string company, int active,int id)
        {
            SqlParameter[] p = new SqlParameter[22];
            p[0] = new SqlParameter("@name", orgName);
            p[0].SqlDbType = SqlDbType.NVarChar;
            p[1] = new SqlParameter("@short", shortDesc);
            p[1].SqlDbType = SqlDbType.NVarChar;
            p[2] = new SqlParameter("@contact", contactId);
            p[2].SqlDbType = SqlDbType.Int;
            p[3] = new SqlParameter("@add1", add1);
            p[3].SqlDbType = SqlDbType.NVarChar;
            p[4] = new SqlParameter("@add2", add2);
            p[4].SqlDbType = SqlDbType.NVarChar;
            p[5] = new SqlParameter("@add3", add3);
            p[5].SqlDbType = SqlDbType.NVarChar;
            p[6] = new SqlParameter("@post", postcode);
            p[6].SqlDbType = SqlDbType.VarChar;
            p[7] = new SqlParameter("@town", town);
            p[7].SqlDbType = SqlDbType.NVarChar;
            p[8] = new SqlParameter("@county", county);
            p[8].SqlDbType = SqlDbType.NVarChar;
            p[9] = new SqlParameter("@country", country);
            p[9].SqlDbType = SqlDbType.NVarChar;
            p[10] = new SqlParameter("@pref", Preferred);
            p[10].SqlDbType = SqlDbType.Int;
            p[11] = new SqlParameter("@express", Express);
            p[11].SqlDbType = SqlDbType.Int;
            p[12] = new SqlParameter("@bus", typebus);
            p[12].SqlDbType = SqlDbType.VarChar;
            p[13] = new SqlParameter("@sic", sic);
            p[13].SqlDbType = SqlDbType.VarChar;
            p[14] = new SqlParameter("@full", fullDes);
            p[14].SqlDbType = SqlDbType.NVarChar;
            p[15] = new SqlParameter("@phone", phone);
            p[15].SqlDbType = SqlDbType.VarChar;
            p[16] = new SqlParameter("@fax", fax);
            p[16].SqlDbType = SqlDbType.VarChar;
            p[17] = new SqlParameter("@web", web);
            p[17].SqlDbType = SqlDbType.VarChar;
            p[18] = new SqlParameter("@charity", charty);
            p[18].SqlDbType = SqlDbType.VarChar;
            p[19] = new SqlParameter("@company", company);
            p[19].SqlDbType = SqlDbType.VarChar;
            p[20] = new SqlParameter("@active", active);
            p[20].SqlDbType = SqlDbType.Int;
            p[21] = new SqlParameter("@id", id);
            p[21].SqlDbType = SqlDbType.Int;
            h.ExecuteNonQuerry("Org_Update", p);
        }
        public void InsertAcc(int id, int refid)
        {
            SqlParameter[] p = new SqlParameter[2];
            p[0] = new SqlParameter("@OrgID", id);
            p[0].SqlDbType = SqlDbType.Int;
            p[1] = new SqlParameter("@Refid", refid);
            p[1].SqlDbType = SqlDbType.Int;
            h.ExecuteNonQuerry("Org_InsertAcc", p);
        }

        public void InsertBarrier(int id, int refid)
        {
            SqlParameter[] p = new SqlParameter[2];
            p[0] = new SqlParameter("@OrgID", id);
            p[0].SqlDbType = SqlDbType.Int;
            p[1] = new SqlParameter("@Refid", refid);
            p[1].SqlDbType = SqlDbType.Int;
            h.ExecuteNonQuerry("Org_InsertBarrier", p);
        }

        public void InsertBenefit(int id, int refid)
        {
            SqlParameter[] p = new SqlParameter[2];
            p[0] = new SqlParameter("@OrgID", id);
            p[0].SqlDbType = SqlDbType.Int;
            p[1] = new SqlParameter("@Refid", refid);
            p[1].SqlDbType = SqlDbType.Int;
            h.ExecuteNonQuerry("Org_InsertBenefit", p);
        }

        public void InsertDisa(int id, int refid)
        {
            SqlParameter[] p = new SqlParameter[2];
            p[0] = new SqlParameter("@OrgID", id);
            p[0].SqlDbType = SqlDbType.Int;
            p[1] = new SqlParameter("@Refid", refid);
            p[1].SqlDbType = SqlDbType.Int;
            h.ExecuteNonQuerry("Org_InsertDisa", p);
        }

        public void InsertEthnic(int id, int refid)
        {
            SqlParameter[] p = new SqlParameter[2];
            p[0] = new SqlParameter("@OrgID", id);
            p[0].SqlDbType = SqlDbType.Int;
            p[1] = new SqlParameter("@Refid", refid);
            p[1].SqlDbType = SqlDbType.Int;
            h.ExecuteNonQuerry("Org_InsertEthnic", p);
        }
        public void InsertOEOIPro(int id, int refid)
        {
            SqlParameter[] p = new SqlParameter[2];
            p[0] = new SqlParameter("@OrgID", id);
            p[0].SqlDbType = SqlDbType.Int;
            p[1] = new SqlParameter("@Refid", refid);
            p[1].SqlDbType = SqlDbType.Int;
            h.ExecuteNonQuerry("Org_InsertOEOIPro", p);
        }
        public void InsertOEOISer(int id, int refid)
        {
            SqlParameter[] p = new SqlParameter[2];
            p[0] = new SqlParameter("@OrgID", id);
            p[0].SqlDbType = SqlDbType.Int;
            p[1] = new SqlParameter("@Refid", refid);
            p[1].SqlDbType = SqlDbType.Int;
            h.ExecuteNonQuerry("Org_InsertOEOISer", p);
        }

        public void InsertPerso(int id, int refid)
        {
            SqlParameter[] p = new SqlParameter[2];
            p[0] = new SqlParameter("@OrgID", id);
            p[0].SqlDbType = SqlDbType.Int;
            p[1] = new SqlParameter("@Refid", refid);
            p[1].SqlDbType = SqlDbType.Int;
            h.ExecuteNonQuerry("Org_InsertPerso", p);
        }

        public void InsertSpec(int id, int refid)
        {
            SqlParameter[] p = new SqlParameter[2];
            p[0] = new SqlParameter("@OrgID", id);
            p[0].SqlDbType = SqlDbType.Int;
            p[1] = new SqlParameter("@Refid", refid);
            p[1].SqlDbType = SqlDbType.Int;
            h.ExecuteNonQuerry("Org_InsertSpec", p);
        }
        //
        public void DelAcc(int id)
        {
            SqlParameter[] p = new SqlParameter[1];
            p[0] = new SqlParameter("@id", id);
            p[0].SqlDbType = SqlDbType.Int;
            h.ExecuteNonQuerry("Org_DelAcc", p);
        }

        public void DelBarrier(int id)
        {
            SqlParameter[] p = new SqlParameter[1];
            p[0] = new SqlParameter("@id", id);
            p[0].SqlDbType = SqlDbType.Int;
            h.ExecuteNonQuerry("Org_DelBarrier", p);
        }

        public void DelBenefit(int id)
        {
            SqlParameter[] p = new SqlParameter[1];
            p[0] = new SqlParameter("@id", id);
            p[0].SqlDbType = SqlDbType.Int;
            h.ExecuteNonQuerry("Org_DelBenefit", p);
        }
        public void DelOEOIPro(int id)
        {
            SqlParameter[] p = new SqlParameter[1];
            p[0] = new SqlParameter("@id", id);
            p[0].SqlDbType = SqlDbType.Int;
            h.ExecuteNonQuerry("Org_DelOEOIPro", p);
        }
        public void DelOEOISer(int id)
        {
            SqlParameter[] p = new SqlParameter[1];
            p[0] = new SqlParameter("@id", id);
            p[0].SqlDbType = SqlDbType.Int;
            h.ExecuteNonQuerry("Org_DelOEOISer", p);
        }

        public void DelDisa(int id)
        {
            SqlParameter[] p = new SqlParameter[1];
            p[0] = new SqlParameter("@id", id);
            p[0].SqlDbType = SqlDbType.Int;
            h.ExecuteNonQuerry("Org_DelDisa", p);
        }

        public void DelEthnic(int id)
        {
            SqlParameter[] p = new SqlParameter[1];
            p[0] = new SqlParameter("@id", id);
            p[0].SqlDbType = SqlDbType.Int;
            h.ExecuteNonQuerry("Org_DelEthnic", p);
        }

        public void DelPerso(int id)
        {
            SqlParameter[] p = new SqlParameter[1];
            p[0] = new SqlParameter("@id", id);
            p[0].SqlDbType = SqlDbType.Int;
            h.ExecuteNonQuerry("Org_DelPerso", p);
        }

        public void DelSpec(int id)
        {
            SqlParameter[] p = new SqlParameter[1];
            p[0] = new SqlParameter("@id", id);
            p[0].SqlDbType = SqlDbType.Int;
            h.ExecuteNonQuerry("Org_DelSpec", p);
        }
        //

        public DataTable GetdataById(int id)
        {
            SqlParameter[] p = new SqlParameter[1];
            p[0] = new SqlParameter("@id", id);
            p[0].SqlDbType = SqlDbType.Int;
            return h.GetData("Org_GetdataByID", p);
        }
        public DataTable GetAccById(int id)
        {
            SqlParameter[] p = new SqlParameter[1];
            p[0] = new SqlParameter("@id", id);
            p[0].SqlDbType = SqlDbType.Int;
            return h.GetData("Org_GetAccredByID", p);
        }
        public DataTable GetEthnicById(int id)
        {
            SqlParameter[] p = new SqlParameter[1];
            p[0] = new SqlParameter("@id", id);
            p[0].SqlDbType = SqlDbType.Int;
            return h.GetData("Org_GetEthniccapaByID", p);
        }
        public DataTable GetSpecById(int id)
        {
            SqlParameter[] p = new SqlParameter[1];
            p[0] = new SqlParameter("@id", id);
            p[0].SqlDbType = SqlDbType.Int;
            return h.GetData("Org_GetOrgSpecByID", p);
        }
        public DataTable GetOEOIProById(int id)
        {
            SqlParameter[] p = new SqlParameter[1];
            p[0] = new SqlParameter("@id", id);
            p[0].SqlDbType = SqlDbType.Int;
            return h.GetData("Org_GetOEOIProByID", p);
        }
        public DataTable GetOEOISerById(int id)
        {
            SqlParameter[] p = new SqlParameter[1];
            p[0] = new SqlParameter("@id", id);
            p[0].SqlDbType = SqlDbType.Int;
            return h.GetData("Org_GetOEOISerByID", p);
        }
        public DataTable GetBarriersById(int id)
        {
            SqlParameter[] p = new SqlParameter[1];
            p[0] = new SqlParameter("@id", id);
            p[0].SqlDbType = SqlDbType.Int;
            return h.GetData("Org_GetSerBarrieCapaByID", p);
        }
        public DataTable GetBenefitById(int id)
        {
            SqlParameter[] p = new SqlParameter[1];
            p[0] = new SqlParameter("@id", id);
            p[0].SqlDbType = SqlDbType.Int;
            return h.GetData("Org_GetSerBenifitCapaByID", p);
        }
        public DataTable GetDisaById(int id)
        {
            SqlParameter[] p = new SqlParameter[1];
            p[0] = new SqlParameter("@id", id);
            p[0].SqlDbType = SqlDbType.Int;
            return h.GetData("Org_GetSerDisaCapaByID", p);
        }
        public DataTable GetPersoById(int id)
        {
            SqlParameter[] p = new SqlParameter[1];
            p[0] = new SqlParameter("@id", id);
            p[0].SqlDbType = SqlDbType.Int;
            return h.GetData("Org_GetSerPersoCapaByID", p);
        }
        public bool CheckName(string name)
        {
            SqlParameter[] p = new SqlParameter[1];
            p[0] = new SqlParameter("@org", name);
            p[0].SqlDbType = SqlDbType.NVarChar;
            return (h.GetValueString("Org_CheckName", p) == "T");
        }

    }
}